﻿/*
    * Designer:       Virgil  
    * Description:    The interface of the Sudoku
    * Created:         06/07/2010
    * History:
==============================================================
    * Author      DateTime        Alter Description
==============================================================
    */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace SudokuWPF
{
    //MarshalByRefObject 允许在支持远程处理的应用程序中跨应用程序域边界访问对象。
    public class SudokuSolverContainer:MarshalByRefObject, ISudokuSolver
    {
        ISudokuSolver solver;
        #region ISudokuSolver 成员

        public string Name
        {
            get { return solver.Name; }
        }

        public string Description
        {
            get { return solver.Description; }
        }

        public string Author
        {
            get { return solver.Author; }
        }

        public bool Solve(ref int?[,] board)
        {
            return solver.Solve(ref board);
        }
        #endregion

        #region 方法
        public void Init(Type t)
        {
            solver = Activator.CreateInstance(t) as ISudokuSolver;//获取对现有远程对象的引用创建指实例
        }
        #endregion
    }

    //数独解题器接口
    public interface ISudokuSolver
    {
        #region 属性
        string Name
        { get; }
        string Description
        { get; }
        string Author
        { get; }
        #endregion
        #region 方法
        bool Solve(ref int?[,] board);
        #endregion
    }

    public class SolverResult : DependencyObject
    {
        TimeSpan timeTaken; //花费时间
        bool failed;        //标识题目是否有解
        ISudokuSolver solver;

        #region 属性
        public TimeSpan TimeTaken
        {
            get
            {
                return timeTaken;
            }
            set
            {
                timeTaken = value;
            }
        }       
        public ISudokuSolver Solver
        {
            get
            {
                return solver;
            }
            set
            {
                solver = value;
            }
        }      
        public bool Failed
        {
            get
            {
                return failed;
            }
            set
            {
                failed = value;
            }
        }
        #endregion
    }
}
